﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using System;
using System.IO;
public class Test : MonoBehaviour
{
    public Texture2D texture;
    void OnGUI()
    {
        if (GUI.Button(new Rect(10, 10, 150, 100), "I am a button"))
        {
            /*  Color t = new Color(1, 0, 1);
              Debug.LogError(t.grayscale);
              Debug.LogError(t.maxColorComponent);
              int num =(int) (t.r * 255 * 16 * 16 * 16 * 16 + t.g * 255 * 16 * 16 + t.b * 255);*/
            // Debug.LogError(Convert.ToString(num, 16));

            string str = "return {";
            Color[] textureCol = texture.GetPixels();
            for(int y = texture.height-1; y >= 0; y--)
            {
                str += "{";
                Color t; int num;
                for (int x = 0; x < texture.width; x++)
                {
                    t = textureCol[y*texture.width+x];
                    //num =(int)(t.r * 0xffffff + t.g * 0x100ff + t.b * 0xff);
                    str += String.Format("0x{0},", ColorUtility.ToHtmlStringRGB(t));
                }
                str += "},";
            }
            str += "}";
            File.WriteAllText("C:\\Users\\Administrator\\Desktop\\img.lua", str);
            Debug.LogError("完成");
        }
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
